<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page language="java" import="java.util.*" %>
<jsp:directive.page import="com.xr.common.CommUtil"/>
<jsp:directive.page import="com.bstek.dorado.data.db.*"/>
<jsp:directive.page import="com.bstek.dorado.utils.variant.VariantSet"/>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title></title>
<script language="javascript" src="<%=request.getContextPath()%>/dorado/smartweb2.loadUserLib.d?file=/lib/jquery1.8.2.min.js"></script>
 <script  src="<%=request.getContextPath()%>/dorado/smartweb2.loadUserLib.d?file=/lib/highcharts2.3.5.js"></script>
<script   src="<%=request.getContextPath()%>/dorado/smartweb2.loadUserLib.d?file=/lib/exporting2.3.5.js"></script>
<script type="text/javascript"> 
		 	<%
			DBStatement dbs=new  DBStatement();
			int cmc=0;
			String pgid=request.getParameter("positionGroupId");
			dbs.setSql("select group_type from pb_position_group where super_position_group_id="+pgid);
			VariantSet vst=dbs.query();
			if(vst==null){
			out.write("</script><body>无数据被统计！<body>"); return;
			}
			
		String cfc="",c="",xl="";
		int sum=0; 
		
		if(vst.getInt("GROUP_TYPE")==1){
		    dbs.setSql("select count(1) pc from pb_position_group pg,pb_position_group_sub pgs where pg.position_group_id=pgs.position_group_id and "+
			" pg.super_position_group_id="+pgid);
			sum=dbs.query().getInt(0);
			dbs.setSql("select pg.position_group_id,pg.position_group_name,count(1) pc from pb_position_group pg,pb_position_group_sub pgs where pg.position_group_id=pgs.position_group_id "+
			" and pg.super_position_group_id="+pgid+" group by pg.position_group_id,pg.position_group_name");
			List list=dbs.queryForList();
			if(list.size()==0){out.write("</script><body>无数据被统计！<body>"); return;}
			for(int i=0;i<list.size();i++){
			  VariantSet vs=(VariantSet)list.get(i); 
			   cfc+="['"+vs.getString("position_group_name")+"',"+(vs.getInt("PC")*100/sum)+"],";
			}
		}else{ //岗位分类
		    dbs.setSql("select count(1) pc from org_onoff_station oos where oos.status=2 and exists(select 1 from  pb_position_group pg,pb_position_group_sub pgs where pg.position_group_id=pgs.position_group_id and "+
			" pgs.position_id=oos.position_id and pg.super_position_group_id="+pgid+")");
			sum=dbs.query().getInt(0);
			dbs.setSql("select pg.position_group_id,pg.position_group_name, "+
			"(select count(1)from org_onoff_station oos,pb_position_group_sub pgs  where pg.position_group_id = pgs.position_group_id and oos.position_id = pgs.position_id and oos.status = 2) pc"+
			"  from pb_position_group pg where  pg.super_position_group_id ="+pgid+" ");
			List list=dbs.queryForList();
			if(list.size()==0){out.write("</script><body>无数据被统计！<body>"); return;}
			for(int i=0;i<list.size();i++){
			  VariantSet vs=(VariantSet)list.get(i); 
			   cfc+="['"+vs.getString("position_group_name")+"',"+(vs.getInt("PC")*100/sum)+"],";
			}
		}
		 	
		dbs.close();
			cfc=cfc.substring(0,cfc.length()-1); 
			
		%>
		
		var chart;
			$(document).ready(function() {
				chart = new Highcharts.Chart({
					chart: {
						renderTo: 'container'
					},
					title: {
						text: ''
					},
					plotArea: {
						shadow: null,
						borderWidth: null,
						backgroundColor: null
					},
					tooltip: {
						formatter: function() {
							return '<b>'+ this.point.name +'</b>: '+ this.y +' %';
						}
					},
					plotOptions: {
						pie: {
							allowPointSelect: true,
							cursor: 'pointer',
							dataLabels: {
								enabled: true,
								color: '#000000',
								connectorColor: '#000000',
								formatter: function() {
									return '<b>'+ this.point.name +'</b>: '+ this.y +' %';
								}
							}
						}
					},
				    series: [{
						type: 'pie',
						name: 'Browser share',
						data: [
							<%=cfc%>
						]
					}]
				});
			});
				
		</script>

  </head>
  
  <body>
    <div id="container" style="width: 100%; height: 100%; margin: 0 auto"></div>

  </body>
</html>
